package com.woniuxy.owner.controller;

import com.woniuxy.common.utils.ResponseUtil;
import com.woniuxy.owner.util.MinioUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@CrossOrigin
public class MinioController {

    @Resource
    private MinioUtil minioUtil;

    @PostMapping("/uploadImg")
    public ResponseUtil uploadImg(@RequestParam("file") MultipartFile file ) {

        try {
            ResponseUtil url = minioUtil.uploadFile(file, "xiaowo");
            return url;
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseUtil.error("上传失败");
        }
    }

}
